<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        var sum = 'aabccd'
        var res = ''
        // 循环遍历字符串sum
        for (var i = 0; i < sum.length; i++) {
            // 判断res中是否不存在sum中的元素， 是则加入到res中，否则进行下一次循环
            if (res.indexOf(sum.charAt(i)) === -1) {
                res += sum.charAt(i)
            }
        }
        console.log(res)
    </script>
</body>

</html>